#include "dmp.h"

dmp::dmp(QDate date_, track track_, QList<team*> t)
{
    standings_m.rider_points.resize(14);
    standings_m.team_points.resize(15);
    table_of_heats.heats.resize(15);
    for (int i = 0; i<15; i++)
    {
        table_of_heats.heats[i].start_positions.resize(4);
        table_of_heats.heats[i].number = i;
    }
    QList<QStringList> table_from_file = CSV.read("rules/dmp.csv");
    for (int i = 0; i< table_from_file.size(); i++)
    {
        for (int n = 0; n<4; n++)
        {
            table_of_heats.heats[i].number = i;
            table_of_heats.heats[i].start_positions[n].helmet = table_from_file[i][n][2];
            if (table_from_file[i][n].left(2).toInt() < 8)
                table_of_heats.heats[i].start_positions[n].rider_number = table_from_file[i][n].left(2).toInt()-1;
            else
                table_of_heats.heats[i].start_positions[n].rider_number = table_from_file[i][n].left(2).toInt()-2;
            table_of_heats.heats[i].start_positions[n].number = n;
        }
    }
    teams = t;
    date = date_;
    h = new heat(track_.name);
    event_type = "dmp";
    heat_number = 0;
    containers.resize(2);
}
QStringList dmp::runHeat(QList<rider>& r)
{
    QList<heat_rider*> riders;
    for (int i = 0; i < 4; i++)
    {
        riders << &riders_list[table_of_heats.heats[heat_number].start_positions[i].rider_number]->rider_h;
        riders[i]->clear();
        riders[i]->helmetColour = table_of_heats.heats[heat_number].start_positions[i].helmet;
        riders[i]->startPosition = table_of_heats.heats[heat_number].start_positions[i].number;
    }

    h->runHeat(riders, true);
    QStringList txt;
    QString stra;
    for (int i = 0; i < riders.size(); i++)
    {
        standings_m.rider_points[table_of_heats.heats[heat_number].start_positions[i].rider_number] << 4 - riders[i]->place;
        stra = "<b>" + QString::number(4 - riders[i]->place)+ " " + r[riders[i]->id].surname + "<\b>";
        txt << stra;
    }
    heat_number++;
    return txt;

}
